<template>
  <transition name="fade">
    <div v-dom-portal="'body'" v-if="visible" class="v-modal">
      <div class="modal-content">
        <div class="head">
          <div class="title">{{title}}</div>
          <div class="close" @click="$emit('on-close')">
            <svg-icon name="close" size="22"></svg-icon>
          </div>
        </div>
        <div class="content">
          <slot></slot>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  props: {
    visible: { type: Boolean, required: true, default: false },
    title: { type: String, default: '弹窗' }
  }
}
</script>

<style lang="less" scoped>
.v-modal {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100;
  background-color: rgba(0, 0, 0, .5);
  .modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 14px;
    border: 1px solid rgba(188, 232, 255, 1);
    border-radius: 4px;
    background-color: rgba(33, 52, 84, .9);
    min-width: 200px;
    .head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-bottom: 8px;
      border-bottom: 1px solid rgba(255, 255, 255, .3);
      .title {
        font-size: 18px;
        font-weight: 500;
        color: #fff;
        line-height: 1.5;
      }
      .close {
        width: 22px;
        height: 22px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
      }
    }
  }
}
.fade-enter-active, .fade-leave-active {
  transition: opacity .5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}
</style>
